package cn.kgc.vue.response;

import lombok.Data;

import java.util.HashMap;

/**
 * @author 课工场
 * @date 2024/9/20
 * @description  统一响应结果
 * code  msg  data
 */
@Data
public class ResponseResult {

    // 状态码
    private Integer code;
    // 信息提示
    private String message;
    // 响应需要携带的数据
    private HashMap<String,Object> data = new HashMap<>();

    //  成功
    public static ResponseResult success(){
        ResponseResult responseResult = new ResponseResult();
        responseResult.setCode(ResponseStatus.SUCCESS.getCode());
        responseResult.setMessage(ResponseStatus.SUCCESS.getMessage());
        return  responseResult;
    }

    // 失败
    public static ResponseResult fail(){
        ResponseResult responseResult = new ResponseResult();
        responseResult.setCode(ResponseStatus.FAIL.getCode());
        responseResult.setMessage(ResponseStatus.FAIL.getMessage());
        return  responseResult;
    }

    // 异常
    public static ResponseResult error(){
        ResponseResult responseResult = new ResponseResult();
        responseResult.setCode(ResponseStatus.ERROR.getCode());
        responseResult.setMessage(ResponseStatus.ERROR.getMessage());
        return  responseResult;
    }

    // 设置数据
    public ResponseResult data(String key,Object value){
        this.data.put(key,value);
        return this;
    }

    // 设置提示信息
    public ResponseResult message(String message){
        this.message = message;
        return this;
    }

    // 设置响应状态码
    public ResponseResult code(ResponseStatus responseStatus){
       this.code = responseStatus.getCode();
        return this;
    }




}
